package cn.com.eado.crm.m.repository

import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import cn.com.eado.crm.m.AppExecutors
import cn.com.eado.crm.m.db.AppIcon
import cn.com.eado.crm.model.NetworkBoundResource
import cn.com.eado.crm.model.Resource
import cn.com.eado.crm.m.db.MyDatabase
import cn.com.eado.crm.model.net.ApiResponse

class AppRepository {

    fun load(name: String): LiveData<Resource<List<AppIcon>>> {
        return object: NetworkBoundResource<List<AppIcon>, List<AppIcon>>(AppExecutors()){
            override fun shouldLoadFromDb(): Boolean = true

            override fun loadFromDb(): LiveData<List<AppIcon>> = MyDatabase.getInstance().appIconDao().queryAll()

            override fun createCall() = MediatorLiveData<ApiResponse<List<AppIcon>>>()

            override fun saveCallResult(item: List<AppIcon>) {}

            override fun shouldFetch(data: List<AppIcon>?) = false

            override fun createCall2(): LiveData<ApiResponse<List<AppIcon>>>? = null
        }.asLiveData()
    }
}